package com.woniuxy.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: 马宇航
 * @Todo: 正常退订 订单的队列,让消息变成 死信队列
 * @DateTime: 25/09/01/星期一 16:12
 * @Component: 成都蜗牛学苑
 **/
@Component
public class DeathQueueRefund {
    static int i = 0;
    @RabbitListener(queues = "order.refund")
    public void refund(String order, Channel channel, Message message) throws IOException {
        System.out.println(message);
        if(i++%2==0){
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        }else {
            //拒绝入队false,消息就会变成死信
            channel.basicNack(message.getMessageProperties().getDeliveryTag(),
                    false,false);
        }
    }
}
